import axios, { type InternalAxiosRequestConfig } from "axios";
const instance = axios.create({
    baseURL: 'http://geek.itheima.net/v1_0',
    timeout: 5000
})

instance.interceptors.request.use((config: InternalAxiosRequestConfig) => {
    return config
}, err => {
    return Promise.reject(err)
})

instance.interceptors.response.use(res => {
    return res.data.data
}, err => {
    return Promise.reject(err)
})

export class RequestAxios {
    static get<T>(url: string, params?: object) {
        return instance.get<null, T>(url, { params })
    }
    static post(url: string, data?: any) {
        return instance.post(url, data)
    }
    static put(url: string, data?: any) {
        return instance.put(url, data)
    }
    static delete(url: string, params?: any) {
        return instance.delete(url, { params })
    }
}